package com.bw.announcement.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.announcement.adapter.Cement2Adapter
import com.bw.announcement.databinding.ActivityAnnouncementBinding
import com.bw.announcement.net.AnnouncementViewModel
import com.bw.base.constants.RoutePath
import com.bw.base.constants.UserConst
import com.bw.common.view.BaseMvvmActivity
import com.tencent.mmkv.MMKV

@Route(path = RoutePath.PATH_ANNOUNCEMENT)
class AnnouncementActivity : BaseMvvmActivity<ActivityAnnouncementBinding,AnnouncementViewModel>() {
    private var uid:Int = 0
    private lateinit var adapter: Cement2Adapter
    override fun initView() {
        binding.bar.ivBack.setOnClickListener { finish() }
        binding.bar.tvTitle.text = "公告管理"


        uid = MMKV.defaultMMKV().decodeInt(UserConst.USER_ID)
        adapter = Cement2Adapter()
        binding.rvCement.adapter = adapter
        binding.rvCement.layoutManager = LinearLayoutManager(this)



        vm.getCementsByUid(uid)

    }

    override fun initData() {

        vm.cementSuccess.observe(this){

            adapter.data.clear()
            adapter.data.addAll(it)
            adapter.notifyDataSetChanged()

        }
    }

}